package com.ncell.cell;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class I implements Comparable<I> {

    private float x;
    private float y;
    private float ax;
    private float ay;
    private float priority;
    private final List<PConnection> pField = new ArrayList();
    private final Set<P>connectedP=new HashSet<>();
    private float activation;
    private float moveDesire = 1;

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }

    public boolean containsP(P p) {
        return connectedP.contains(p);
    }

    public boolean isActive() {
        return activation > 0.6;
    }

    public float getAx() {
        return ax;
    }

    public void setAx(float ax) {
        this.ax = ax;
    }

    public float getAy() {
        return ay;
    }

    public void setAy(float ay) {
        this.ay = ay;
    }

    public float getPriority() {
        return priority;
    }

    public void setPriority(float priority) {
        this.priority = priority;
    }

    public void addConnection(PConnection connection){
        pField.add(connection);
        connectedP.add(connection.getP());
    }
    
    public void removeConnection(PConnection connection){
        pField.remove(connection);
        connectedP.remove(connection.getP());
    }
    
    public List<PConnection> getPField() {
        return pField;
    }

    public float getActivation() {
        return activation;
    }

    public void setActivation(float activation) {
        this.activation = activation;
    }

    public float getMoveDesire() {
        return moveDesire;
    }

    public void setMoveDesire(float moveDesire) {
        if(moveDesire>1){
            moveDesire=1;
        }
        if(moveDesire<-1){
            moveDesire=-1;
        }
        
        this.moveDesire = moveDesire;
    }
    
    public boolean canMove(){
        return moveDesire>0.05;
    }

    @Override
    public int compareTo(I o) {
        return (int) ((o.getPriority()-priority) * 1000);
    }

}
